<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>简写一个ajax请求</title>
</head>
<body>
    <script>
        // 1.创建对象
        var xhr;
        if (window.XMLHttpRequest) {
            xhr = new XMLHttpRequest();
        } else {
            // code for IE6,IE5 做兼容
            xhr = new ActiveXObject('Microsoft.XMLHTTP');
        }
        // 2.设置请求方式还有地址
        xhr.open('GET', 'https://www.baidu.com/');
        // 3.发起请求
        xhr.send();
        // 4.注册事件
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    alert(xhr.responseText);
                } else {
                    alert('出错了,Err:' + xhr.status);
                }
            }
        };
    </script>
</body>
</html>